//
//  OutlineItemCellView.m
//  mac2
//
//  Created by 李劭华 on 2021/7/26.
//
#import <Masonry/Masonry.h>
#import "OutlineViewDataModel.h"
#import "OutlineItemCellView.h"
@interface OutlineItemCellView()
@property (nonatomic,strong)NSButton *titleBtn;


@end
@implementation OutlineItemCellView

- (void)drawRect:(NSRect)dirtyRect {
    [super drawRect:dirtyRect];
    
    self.layer = [CALayer layer];
    self.layer.backgroundColor = [NSColor greenColor].CGColor;
    
    
    [self.titleBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.edges.equalTo(self);
    }];
    // Drawing code here.
}

//  OutlineItemCellView.m
- (void)setObjectValue:(id)objectValue {
    [super setObjectValue:objectValue];
    if (self.objectValue) {
        if ([self.objectValue isKindOfClass:[OutlineViewDataModel class]]) {
            OutlineViewDataModel *model = (OutlineViewDataModel *)self.objectValue;
            [self updateControlsForDataObject:model.name];
        }
    }
}
- (void)updateControlsForDataObject:(NSString *)name {
    self.textField.stringValue = name;
    NSString *string = @"这是蓝色文字，这是红色文字。";
    NSMutableAttributedString *colorTitle = [[NSMutableAttributedString alloc] initWithString: string];
    [colorTitle addAttribute:NSForegroundColorAttributeName value:[NSColor blueColor] range:NSMakeRange(0, string.length-1)];

    self.textField.attributedStringValue = colorTitle;
    NSLog(@"self.textField--%@:%@",name,self.textField.stringValue);
    self.titleBtn.title = name;
}

-(NSButton *)titleBtn
{
    if (!_titleBtn) {
        _titleBtn = [[NSButton alloc]init];
        _titleBtn.title =@"jkkjkj";
        _titleBtn.frame = CGRectMake(0 , 0, 200, 40);
        [self addSubview:_titleBtn];
    }
    return _titleBtn;
}

@end
